package testcase;

import player.*;
import io.*;
import card.*;
import junit.framework.TestCase;

public class PlayerIntegratedTest extends TestCase {
	private Player player;

	private class IOStub extends IOManager {

		private int ratingCount;

		public Cardset ioPlayerSelectCards(Cardset hand, String playerName) {
			Cardset play = new Cardset(3);
			play.add(hand.getCard(0));
			return play;
		}

		public int ioPlayerLandlordRating(String playerName, Cardset hand) {
			if (ratingCount == 0) {
				ratingCount++;
				return 1;
			}
			return 3;
		}
	}

	public void setUp() {
		player = new Player("Derek", 52212006, new IOStub());
	}

	public void tearDown() {
	}

	/**
	 * Test case 1: function getName
	 */
	public void testGetName() {
		assertEquals(player.getName(), "Derek");
	}

	/**
	 * Test case 2: getID
	 */
	public void testGetID() {
		assertEquals(player.getID(), 52212006);
	}

	/**
	 * Test case 3: deal card to hand and count it
	 */
	public void testDealCards() {
		player.deckDeal2Hand(new Card('s', 'A'));
		player.deckDeal2Hand(new Card('s', '2'));
		assertEquals(player.countHand(), 2);
	}

	/**
	 * Test case 4: clear the card
	 */
	public void testClearCards() {
		player.deckDeal2Hand(new Card('s', 'A'));
		player.deckDeal2Hand(new Card('s', '2'));
		player.clearHand();
		assertEquals(player.countHand(), 0);
	}

	/**
	 * Test case 5: rate for choosing to be a landlord
	 */
	public void testLandLordRating() {
		assertEquals(player.landLordRating(), 1);
		assertEquals(player.landLordRating(), 3);
	}

	/**
	 * Test case 6: player process on one turn
	 */
	public void testOneTurn() {
		player.deckDeal2Hand(new Card('s', 'A'));
		player.deckDeal2Hand(new Card('h', '2'));
		player.startTurn();
		assertEquals(player.countPlay(), 1);
		player.endTurn();
		assertEquals(player.countPlay(), 0);
		player.endTurn();
		assertEquals(player.countPlay(), 0);
		player = new Player("Derek", 52212006, new IOStub());
	}

	public void testCopyConstructor() {
		Player a = new Player("test", 2, new IOManager());
		a.deckDeal2Hand(new Card('s', 'A'));
		a.deckDeal2Hand(new Card('h', '2'));
		Player b = new Player(a);
		assertEquals(a.getName(), b.getName());
		assertEquals(a.countHand(), b.countHand());
	}
}
